package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.PremisesTypeCountResDto;
import com.yixun.qfbao.apidto.base.CommonReqDTO;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.GeneralReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("premisesTypeCountHander")
public class PremisesTypeCountHander extends CommonAbstractHander {

    private Logger logger = LoggerFactory.getLogger(PremisesTypeCountHander.class);

    @Autowired
    private PremisesApiService premisesApiService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        GeneralReqVo<CommonReqDTO> reqVo = (GeneralReqVo<CommonReqDTO>) reqDto;
        CommonReqDTO commonReqDTO = reqVo.getParams();
        BaseResponseDTO<PremisesTypeCountResDto> res = new BaseResponseDTO<>();
        PremisesTypeCountResDto resDto = new PremisesTypeCountResDto();
        try {
            resDto = premisesApiService.premisesTypeCount(commonReqDTO);
        } catch (TServerException t) {
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(t.getErrorMsg());
        } catch (Exception e) {
            logger.error("premisesTypeCountHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("获取楼盘分类统计失败！");
        }
        res.setResult(resDto.getResult());
        res.setResData(resDto);
        return res;
    }
}
